package algorithm;

public class TheContainerThatHoldsTheMostWater {
    public static void main(String[] args) {
        int[] array = new int[]{1,8,6,2,5,4,8,3,7};
        System.out.println(maxAreaV(array));
    }

    public static int maxArea(int[] height) {
          //定义前后双指针
          int left = 0,right = height.length - 1,ret = 0;
          while(left < right) {
              //存储计算过程之中较大的体积
              int v = Math.min(height[left],height[right])*(right - left);
              ret = Math.max(v,ret);
              //更新双指针的值
              if(height[left] <= height[right]) {
                  left++;
              } else {
                  right--;
              }
          }
          return ret;
    }

    public static int maxAreaV(int[] height) {
        //直接暴力解
        int ret = 0;
        for (int i = 0; i < height.length; i++) {
            for (int j = i; j < height.length; j++) {
                int v = Math.min(height[i],height[j])*(j - i);
                ret = Math.max(ret,v);
            }
        }

        return ret;
    }
}
